

{% extends "_base.html" %}

{% block main %}

<script>
    $(function () {
        $('#signinForm').submit(function (e) {
            e.preventDefault();
            var md5pw = md5($('#password').val())
            var data = {
                username: $('#username').val(),
                password: md5pw
            };
            $.ajax({
                type: 'POST',
                url: '/api/login',
                data: JSON.stringify(data),
                success: function (resp) {
                    if (resp.code === 200) {
                        alert('登录成功,即将进入首页')
                        location.assign('/home');
                    } else {
                        alert(resp.info)
                    }
                },
                contentType: 'application/json',
                dataType: 'json'
            });
        });
    });
</script>

<form id="signinForm">
    <div class="form-group">
        <p id="error" class="text-danger"></p>
    </div>
    <div class="form-group">
        <label>用户名</label>
        <input id="username" type="text" class="form-control" placeholder="请输入用户名">
    </div>
    <div class="form-group">
        <label>密码</label>
        <input id="password" type="password" class="form-control" placeholder="请输入密码">
    </div>
    <button type="submit" class="btn btn-outline-primary">登录</button>
</form>

{% endblock %}